package com.ruoyi.system.utils;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class GZipFileCompressor {
    public static void compressFile(List<String> files, String compressedFilePath) throws IOException {
       FileOutputStream fos = new FileOutputStream(compressedFilePath);
             ZipOutputStream zos = new ZipOutputStream(fos);
            for (String file : files) {
                try (FileInputStream fis = new FileInputStream(file)) {
                    File f = new File(file);
                    ZipEntry zipEntry = new ZipEntry(f.getName());
                    zos.putNextEntry(zipEntry);
                    byte[] buffer = new byte[1024];
                    int len;
                    while ((len = fis.read(buffer)) > 0) {
                        zos.write(buffer, 0, len);
                    }
                }catch (IOException e) {
            e.printStackTrace();
        }
            }




    }

    public static void main(String[] args) {
        List<String> files = new ArrayList<>();
        files.add("D:/Rworks/demo/result/ACC.tiff");
        files.add("D:/Rworks/demo/result/ACC_P_sum_bubble.tiff");
        //files.add("D:/Rworks/demo/result/batch_PFSunivariate.txt");
        //files.add("D:/Rworks/demo/result/batch_TMEscore.txt");
        try {
            compressFile(files, "D:/Rworks/demo/result/"+System.currentTimeMillis()+"rfiles.zip");
            System.out.println("File compressed successfully.");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
